<template>
    <!-- 添加或修改发货单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="发货编码" prop="nos">
                                <el-input v-model="form.nos" placeholder="请输入发货编码" disabled/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item label="客户名称" prop="kehuName">
                            <el-input v-model="form.kehuName" placeholder="请输入客户名称" disabled/>
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item label="发货总金额" prop="allMoney">
                            <el-input v-model="form.allMoney" placeholder="请输入发货总金额" disabled/>
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="发货日期" prop="fahuoDate">
                                <el-date-picker clearable disabled
                                                v-model="form.fahuoDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择发货日期">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="交货日期" prop="jiaohuoDate">
                                <el-date-picker clearable disabled
                                                v-model="form.jiaohuoDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择交货日期">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="联系人" prop="linkman">
                                <el-input v-model="form.linkman" placeholder="请输入联系人" disabled/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="联系电话" prop="linktel">
                                <el-input v-model="form.linktel" placeholder="请输入联系电话" disabled/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="业务经理及电话" prop="jingli">
                                <el-input v-model="form.jingli" placeholder="请输入业务经理及电话" disabled/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                          <el-form-item label="收货地址" prop="address">
                            <el-input v-model="form.address" placeholder="请输入收货地址" disabled/>
                          </el-form-item>
                        </el-col>
                      <!-- <el-col :span="12">
                           <el-form-item label="发票编号" prop="taxNo">
                               <el-input v-model="form.taxNo" placeholder="请输入发票编号"/>
                           </el-form-item>
                       </el-col>
                       <el-col :span="12">
                           <el-form-item label="发票代码" prop="taxCode">
                               <el-input v-model="form.taxCode" placeholder="请输入发票代码"/>
                           </el-form-item>
                       </el-col>
                       <el-col :span="12">
                           <el-form-item label="发票日期" prop="taxDate">
                               <el-date-picker clearable
                                               v-model="form.taxDate"
                                               type="date"
                                               value-format="yyyy-MM-dd"
                                               placeholder="请选择发票日期">
                               </el-date-picker>
                           </el-form-item>
                       </el-col>
                       <el-col :span="12">
                           <el-form-item label="已开票金额" prop="taxMoney">
                               <el-input v-model="form.taxMoney" placeholder="请输入已开票金额"/>
                           </el-form-item>
                       </el-col>
                       <el-col :span="12">
                           <el-form-item label="剩余开票金额" prop="taxShengyu">
                               <el-input v-model="form.taxShengyu" placeholder="请输入剩余开票金额"/>
                           </el-form-item>
                       </el-col>
                       <el-col :span="12">
                           <el-form-item label="需开票总金额" prop="taxAllmoeny">
                               <el-input v-model="form.taxAllmoeny" placeholder="请输入需开票总金额"/>
                           </el-form-item>
                       </el-col>
                       <el-col :span="12">
                           <el-form-item label="发货总金额" prop="allMoney">
                               <el-input v-model="form.allMoney" placeholder="请输入发货总金额"/>
                           </el-form-item>
                       </el-col>
                       <el-col :span="12">
                           <el-form-item label="剩余回款金额" prop="shengyu">
                               <el-input v-model="form.shengyu" placeholder="请输入剩余回款金额"/>
                           </el-form-item>
                       </el-col>
                       <el-col :span="12">
                           <el-form-item label="回款金额" prop="yihui">
                               <el-input v-model="form.yihui" placeholder="请输入回款金额"/>
                           </el-form-item>
                       </el-col>
                        <el-col :span="12">
                            <el-form-item label="到货日期" prop="daohuoDate">
                                <el-date-picker clearable
                                                v-model="form.daohuoDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择到货日期">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>-->
                      <el-col :span="24">
                        <el-form-item label="备注" prop="remark">
                          <el-input v-model="form.remark" placeholder="请输入备注"disabled/>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  <el-col :span="24">
                    <el-form-item label="弃审原因" prop="name">
                      <el-input v-model="form.name" placeholder="请输入弃审原因"/>
                    </el-form-item>
                  </el-col>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { addAction, getById, updateAction } from '@/api/manage';
    import moment from 'moment';

    export default {
        name: "LvYifahuoForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                url: {
                    getById:'/lvYifahuo/lvYifahuo/',
                    add:'/lvYifahuo/lvYifahuo/add',
                    bohui:'/lvYifahuo/lvYifahuo/bohui',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    id: null,
                    delFlag: null,
                    createBy: null,
                    createTime: null,
                    updateBy: null,
                    updateTime: null,
                    remark: null,
                    nos: null,
                    name: null,
                    fahuoDate: null,
                    jiaohuoDate: null,
                    linkman: null,
                    linktel: null,
                    address: null,
                    status: "0",
                    jingli: null,
                    kehuId: null,
                    kehuName: null,
                    taxNo: null,
                    taxCode: null,
                    taxDate: null,
                    taxMoney: null,
                    taxShengyu: null,
                    taxAllmoeny: null,
                    allMoney: null,
                    shengyu: null,
                    yihui: null,
                    daohuoDate: null,
                    daohuoFile: null,
                    tongzhiId: null,
                    tongzhiNo: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加发货单";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改发货单";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.bohui, this.form).then(response => {
                                this.$modal.msgSuccess("操作成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
